<template>
  <el-tabs v-model="type" @tab-click="handleClick">
    <el-tab-pane label="全部" name="1"/>
    <el-tab-pane label="已通过考试" name="2"/>
    <el-tab-pane label="未通过考试" name="3"/>
    <el-tab-pane label="缺考情况" name="4"/>
    <div class="head-container">
      <el-input v-model="userName" clearable placeholder="学员姓名" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="init">搜索</el-button>
    </div>
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column prop="userName" align="center" label="学员姓名" width="150"/>
      <el-table-column prop="source" align="center" label="得分"/>
      <el-table-column prop="rightCount" align="center" label="答对题数"/>
      <el-table-column prop="wrongCount" align="center" label="答错题数"/>
      <el-table-column prop="useTime" align="center" label="所用时长(秒)">
        <template slot-scope="scope">
          <span>{{formatSeconds(scope.row.useTime)}}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </el-tabs>
</template>
<script>
  import initData from '@/mixins/initData'
  import { formatSeconds } from '@/utils/index'

  export default {
    mixins: [initData],
    data() {
      return {
        userName: '',
        type: '1',
        queryId: this.$route.query.id

      }
    },
    created() {
      this.$nextTick(() => {
        this.init()
      })
    },
    methods: {
      formatSeconds,
      beforeInit() {
        this.url = 'check/user-record/page-list'
        this.params = {
          page: this.page,
          size: this.size,
          userName: this.userName,
          checkId: this.queryId,
          type: this.type
        }
        return true
      },
      handleClick(tab, event) {
        this.init()
      }
    }
  }
</script>
